package com.hao.wms.mvc;

import com.hao.wms.domain.Client;
import com.hao.wms.query.ClientQueryObject;
import com.hao.wms.service.IClientService;
import com.hao.wms.util.RequiredPermission;
import com.opensymphony.xwork2.interceptor.annotations.InputConfig;

import java.io.IOException;

public class ClientAction extends BaseAction{
	/**
	 * 
	 */
	private IClientService clientService;
	
	
	private Client client = new Client();
	
	public Client getClient() {
		return client;
	}
	public void setClient(Client client) {
		this.client = client;
	}
	private ClientQueryObject queryObject = new ClientQueryObject();
	
	
	public ClientQueryObject getQueryObject() {
		return queryObject;
	}
	public void setQueryObject(ClientQueryObject queryObject) {
		this.queryObject = queryObject;
	}
	public void setClientService(IClientService clientService) {
		this.clientService = clientService;
	}
	@InputConfig(methodName = "input")
	@RequiredPermission(value="Client列表")
	public String execute() {
		putContext(PAGERESULT, clientService.query(queryObject));
		
		return LIST;
	}
	@RequiredPermission(value="新增/修改Client")
	public String input() {
		if(client.getId()!=null) {
			client = clientService.get(client.getId());
		}
		return INPUT;
	}
	@RequiredPermission(value="修改Client")
	public String saveOrUpdate() {
		try {
			if(client.getId()!=null) {
                clientService.update(client);
                addActionMessage("修改成功");
            }else {
                clientService.save(client);
                addActionMessage("保存成功");
            }
		} catch (Exception e) {
			e.printStackTrace();
			addActionError(e.getMessage());
		}
		return SUCCESS;
	}
	public void prepareSaveOrUpdate(){
		if(client.getId()!=null) {
			client = clientService.get(client.getId());
			
		}
	}
	@RequiredPermission(value="删除Client")
	public String delete() throws IOException{
		clientService.delete(client);
		putResponseText("删除成功");
		return NONE;
	}
	
	

}
